home *** CD-ROM | disk | FTP | other *** search
Java Source | 1997-04-20 | 1.2 KB | 45 lines |
- import java.io.*;
- import java.util.Vector;
-
- public class MyStrings implements Serializable {
-
- private static final String FILE = "test";
-
- private Vector v = new Vector();
-
- public static void main(String[] args) {
- MyStrings ms = new MyStrings();
- ms.v.addElement("porcupine");
- ms.v.addElement("turpentine");
- write(ms);
- read();
- }
-
- private static void write(MyStrings ms) {
- try {
- FileOutputStream f = new FileOutputStream(FILE);
- ObjectOutput s = new ObjectOutputStream(f);
- s.writeObject(ms);
- s.close();
- } catch (IOException x) {
- System.out.println(x.getMessage());
- }
- }
-
- private static void read() {
- try {
- FileInputStream f = new FileInputStream(FILE);
- ObjectInput s = new ObjectInputStream(f);
- MyStrings ms = (MyStrings)(s.readObject());
- System.out.println(ms.v.elementAt(0));
- System.out.println(ms.v.elementAt(1));
- s.close();
- } catch (IOException x) {
- System.out.println(x.getMessage());
- } catch (ClassNotFoundException x) {
- System.out.println(x.getMessage());
- }
- }
-
- }
-